package other;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;

public class ConversionOfNumberSystem {
    
    static InOut1 io = new InOut1();
    int n;
    String number;
    int m;
    public ConversionOfNumberSystem() {
        n = io.nextInt();
        number = io.next();
        m = io.nextInt();
    }
    public void convert() {
        Stack<Character> stack = new Stack<Character>();
        int tenNumber = Integer.parseInt(number, n);
        // io.out.println(tenNumber);
        while (tenNumber > 0) {
            int temp = tenNumber % m;
            if (temp < 10) {
                stack.push((char) (temp + 48));
            } else {
                stack.push((char) (temp - 10 + 65));
            }
            tenNumber /= m;
        }
        while (!stack.isEmpty()) {
            io.out.print(stack.pop());
        }
        io.out.println();
    }

    public static void main(String[] args) {
        
            ConversionOfNumberSystem c = new ConversionOfNumberSystem();
            c.convert();
            io.out.flush();
        
        

    }


    

}
class InOut1 {
    BufferedReader br;
    StringTokenizer tok;
    PrintWriter out;
    public InOut1() {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));
    }
    public boolean hasNext() {
        while (tok == null || !tok.hasMoreElements()) {
            try {
                tok = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                return false;
            }
        }
        return true;
    }
    public String next() {
        if (hasNext()) {
            return tok.nextToken();
        }
        return null;
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
}